class_name HItemFactory
extends Node

var item_classes:Dictionary = {}
var prototree:Dictionary = {}

## 注册物品类型映射
## 负责将字符串标识符映射到对应的物品类
## @return Dictionary: 类型标识符到类的映射字典
func _register_item_classes():
	return {
		"item": HItem,           # 基础物品类
		"weapon": HWeapon,       # 武器类
		"throwable": HThrowableWeapon  # 投掷武器类
	}

func _init() -> void:
	item_classes = _register_item_classes()
	load_prototree()


func create_item(type: String, data: Dictionary = {}) -> HItem:
	var item_data = prototree.get(type,data) if data.is_empty() else data
	var item_inherit = item_data.get("inherit","")
	var item_class = item_classes.get(item_inherit, HItem)
	var item = item_class.new()
	item.load_data(item_data)
	return item

func load_prototree():
	pass

func create_item_check(type: String, data: Dictionary = {}):
	var item_data = prototree.get(type,data) if data.is_empty() else data
	var item_inherit = item_data.get("inherit","")
	var item_class = item_classes.get(item_inherit, HItem)
	var item = item_class.new()
	item.load_data(item_data)
	return item
